package cj.web.marry.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;

/**
 * 
 * @author 
 *
 */
@DAO
public interface CmpActDAO{
	
	@SQL("SELECT id,name FROM Company WHERE deleteFlag=1 ORDER BY orderNo ")
    List<Map> queryCompanyAll();
	
	@SQL("SELECT id,img,type,name,startDate,endDate,price,duration FROM CmpActivity WHERE deleteFlag=1 AND startDate <= now() AND endDate > now() ORDER BY orderNo DESC,endDate DESC ")
    List<Map> queryAllForEndDate();
	
	@SQL("SELECT id,img,type,name,startDate,endDate,price,duration FROM CmpActivity WHERE deleteFlag=1 AND startDate <= now() AND endDate > now() ORDER BY orderNo DESC,endDate DESC LIMIT :1,:2")
    List<Map> queryAllForEndDate(int start,int length);
	
	@SQL("SELECT count(1) FROM CmpActivity WHERE deleteFlag=1 AND startDate <= now() AND endDate > now() ")
    int queryAllForEndDateSize();
		
	@SQL("SELECT * FROM CmpActivity WHERE id=:1 ")
    List<Map> queryById(int id);
	
	@SQL("INSERT INTO CmpActivityOrder (cmpActivityId,orderNo,userId,duration,price,status,deleteFlag,createAt,createUser,updateAt,updateUser) "
			+ "VALUES (:1,:2,:3,:4,:5,2,1,now(),:6,now(),:6)")
	void createCmpActOrder(int cmpActivityId,String orderNo,int userId,String duration,String price,String phone);

	@SQL("SELECT count(1) FROM CmpActivityOrder WHERE deleteFlag=1 AND userId=:1 AND cmpActivityId=:2 ")
    int queryCmpActivityOrderCount(int userId,int cmpActivityId);
	
	@SQL("SELECT a.*,b.name as cmpActivityName,b.img FROM CmpActivityOrder a join CmpActivity b on a.cmpActivityId=b.id WHERE a.deleteFlag=1 AND a.userId=:1 ORDER BY a.updateAt DESC LIMIT :2,:3 ")
    List<Map> queryCmpActivityOrder(int userId,int start,int length);
	
	@SQL("SELECT count(1) FROM CmpActivityOrder WHERE deleteFlag=1 AND userId=:1 ")
    int queryCmpActivityOrderCount(int userId);
	
	@SQL("SELECT * FROM CmpActivityOrder WHERE id=:1 ")
    List<Map> queryCmpActivityOrderById(int id);
	
	@SQL("update CmpActivity set count=count+1 where id=:1")
	void updateCmpActivity(int id);
}